var t = new (require("../../libs/qqmap-wx-jssdk.min.js"))({
    key: "NEHBZ-IP7R4-WCAUL-DC5EM-2O652-MVBAP"
}), e = require("../../utils/config.js");

Page({
    data: {
        address: "",
        latitude: 0,
        longitude: 0,
        imageList: [],
        memo: "",
        signTime: ""
    },
    onLoad: function(e) {
        var a = this;
        wx.getLocation({
            type: "gcj02",
            success: function(e) {
                t.reverseGeocoder({
                    location: {
                        latitude: e.latitude,
                        longitude: e.longitude
                    },
                    success: function(t) {
                        console.log(t), a.setData({
                            address: t.result.formatted_addresses.recommend
                        });
                    },
                    fail: function(t) {
                        console.log(t);
                    }
                }), console.log(JSON.stringify(e)), a.setData({
                    latitude: e.latitude,
                    longitude: e.longitude,
                    markers: [ {
                        id: 0,
                        iconPath: "../../images/ic_position.png",
                        longitude: e.longitude,
                        latitude: e.latitude,
                        width: 30,
                        height: 30
                    } ]
                });
            }
        });
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {},
    previewImage: function(t) {
        var e = this;
        wx.previewImage({
            current: t.target.dataset.src,
            urls: e.data.imageList
        });
    },
    chooseImage: function() {
        var t = this;
        wx.chooseImage({
            count: 1,
            success: function(e) {
                console.log(e), t.setData({
                    imageList: t.data.imageList.concat(e.tempFilePaths)
                });
            }
        });
    },
    getMemo: function(t) {
        this.setData({
            memo: t.detail.value
        });
    },
    sign: function() {
        var t = this, a = wx.getStorageSync("userId"), s = wx.getStorageSync("serviceProviderId");
        if (0 == t.data.imageList.length) {
            var i = {
                userId: a,
                serviceProviderId: s,
                address: t.data.address,
                lng: t.data.longitude,
                lat: t.data.latitude,
                reson: t.data.memo,
                fileId: ""
            };
            console.log(i), wx.showLoading({
                mask: !0
            }), wx.request({
                url: e.urlList.API_MOBILE_SIGN_SIGN,
                method: "POST",
                header: {
                    contentType: "application/json"
                },
                data: i,
                success: function(e) {
                    wx.hideLoading(), 200 == e.data.status ? (wx.showToast({
                        title: "签到成功",
                        duration: 3e3
                    }), t.setData({
                        signTime: e.data.data.signTime
                    })) : 415 == e.data.status ? wx.showModal({
                        title: "系统提示",
                        content: e.data.message,
                        cancelText: "下次再说",
                        confirmText: "立即完善",
                        success: function(t) {
                            t.confirm && wx.navigateTo({
                                url: "/pages/my/editBank"
                            });
                        }
                    }) : 416 == e.data.status ? wx.showModal({
                        title: "系统提示",
                        content: e.data.message,
                        cancelText: "下次再说",
                        confirmText: "实名认证",
                        success: function(t) {
                            t.confirm && wx.navigateTo({
                                url: "/pages/my/realNameAuthentication"
                            });
                        }
                    }) : wx.showToast({
                        title: e.data.message,
                        icon: "none",
                        duration: 3e3
                    });
                }
            });
        } else wx.showLoading({
            mask: !0
        }), wx.uploadFile({
            url: e.urlList.API_TOOLS_UPLOAD_FILE,
            filePath: t.data.imageList[0],
            name: "file",
            success: function(i) {
                var o = JSON.parse(i.data);
                if (200 == o.status) {
                    var n = {
                        userId: a,
                        serviceProviderId: s,
                        address: t.data.address,
                        lng: t.data.longitude,
                        lat: t.data.latitude,
                        reson: t.data.memo,
                        fileId: o.data.fileId
                    };
                    console.log(n), wx.request({
                        url: e.urlList.API_MOBILE_SIGN_SIGN,
                        method: "POST",
                        header: {
                            contentType: "application/json"
                        },
                        data: n,
                        success: function(e) {
                            wx.hideLoading(), 200 == e.data.status ? (wx.showToast({
                                title: "签到成功",
                                duration: 3e3
                            }), t.setData({
                                signTime: e.data.data.signTime
                            })) : 415 == e.data.status ? wx.showModal({
                                title: "系统提示",
                                content: e.data.message,
                                cancelText: "下次再说",
                                confirmText: "立即完善",
                                success: function(t) {
                                    t.confirm && wx.navigateTo({
                                        url: "/pages/my/editBank"
                                    });
                                }
                            }) : 416 == e.data.status ? wx.showModal({
                                title: "系统提示",
                                content: e.data.message,
                                cancelText: "下次再说",
                                confirmText: "实名认证",
                                success: function(t) {
                                    t.confirm && wx.navigateTo({
                                        url: "/pages/my/realNameAuthentication"
                                    });
                                }
                            }) : wx.showToast({
                                title: e.data.message,
                                icon: "none",
                                duration: 3e3
                            });
                        }
                    });
                } else wx.hideLoading(), wx.showToast({
                    title: i.data.message,
                    icon: "none",
                    duration: 3e3
                });
            }
        });
    }
});